package com.lanp.native_test.controller;

import com.lanp.native_test.common.DataSourceCSV;
import com.lanp.native_test.common.RoutingWith;
import com.lanp.native_test.config.aspect.RoutingAspect;
import com.lanp.native_test.dao.EventMapper;
import com.lanp.native_test.model.Event;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("test")
public class TestRest {
    @Autowired
    private EventMapper eventMapper;

    @Autowired
    private RoutingAspect payCmt;

    /**
     * 单机/多机调用不同db库
     *
     * @param a
     * @return
     */
    @GetMapping("/a")
    public Object testa(Long a) {
        String a1 = payCmt.getA();
        System.out.println("a1 = " + a1);
        Event event = eventMapper.selectByPrimaryKey(a);
        // TODO:
        return event;
    }

    /**
     * 单机/多机调用不同db库
     *
     * @param a
     * @return
     */
    @RoutingWith(DataSourceCSV.slaveDataSource)
    @GetMapping("/b")
    public Object testb(Long a) {
        String a1 = payCmt.getA();
        System.out.println("a1 = " + a1);
        Event event = eventMapper.selectByPrimaryKey(a);
        // TODO:
        return event;
    }

    /**
     * 单机/多机调用不同db库
     *
     * @param a
     * @return
     */
    @RoutingWith(DataSourceCSV.slave3308DataSource)
    @GetMapping("/c")
    public Object testc(Long a) {
        String a1 = payCmt.getA();
        System.out.println("a1 = " + a1);
        Event event = eventMapper.selectByPrimaryKey(a);
        // TODO:
        return event;
    }

}
